package com.guoxianwei.scm.web.actions;

import java.io.StringReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.SessionScope;
import net.sourceforge.stripes.action.StreamingResolution;
import net.sourceforge.stripes.integration.spring.SpringBean;

import com.guoxianwei.scm.domain.Account;
import com.guoxianwei.scm.domain.MenuItem;
import com.guoxianwei.scm.service.MenuItemService;
import com.guoxianwei.scm.web.ajaxresult.AjaxResult;
import com.guoxianwei.util.GSONUtils;

@SessionScope
public class MenuItemActionBean extends AbstractActionBean {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3053806348495660710L;
	
	private static final Log LOGGER = LogFactory.getLog(MenuItemActionBean.class);

	@SpringBean
	private transient MenuItemService menuItemService;
	
	private String menuno;

	public String getMenuno() {
		return menuno;
	}

	public void setMenuno(String menuno) {
		this.menuno = menuno;
	}
	@DefaultHandler
	public Resolution searchMenuItem() {
		Account account = super.getAccount();
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("userid", account.getUserid());
		param.put("menuno", getMenuno());

		List<MenuItem> menuItems = menuItemService
				.getMenuItemByMenuno(param);

		return new StreamingResolution("text", new StringReader(AjaxResult.success(menuItems).toString()));
	}
}
